package com.android.lovely.ui.chat

import android.graphics.Color
import androidx.core.text.bold
import androidx.core.text.buildSpannedString
import androidx.recyclerview.widget.RecyclerView
import com.android.lovely.R
import com.android.lovely.databinding.LayoutChatIntroBinding
import com.android.lovely.databinding.LayoutChatTipBinding
import com.android.lovely.framework.BaseAdapter
import com.kotlin.extensions.appContext
import com.kotlin.extensions.view.ViewExt.clickable

/**
 *
 * @author why
 * @date 2025/3/27 16:28
 */
class ChatTipAdapter : BaseAdapter<String, LayoutChatTipBinding>() {
    override fun bindViewWithHolderDetails(
        holder: ViewHolder,
        item: String?,
        binding: LayoutChatTipBinding,
        position: Int
    ) {

    }

}

class ChatIntroAdapter : BaseAdapter<String, LayoutChatIntroBinding>() {
    private var recyclerView: RecyclerView? = null

    override fun bindViewWithHolderDetails(
        holder: ViewHolder,
        item: String?,
        binding: LayoutChatIntroBinding,
        position: Int
    ) {
        item ?: return
        binding.tvContent.setIndicatorTint(binding.root.context.resources.getColor(R.color.white_ddd))
        binding.tvContent.text = buildSpannedString {
            bold {
                append(binding.root.context.getString(R.string.intro))
            }
            append(item.trim())
        }
        binding.tvContent.clickable {
            holder.binding.tvContent.switchExpandState()
            val itemCount = recyclerView?.adapter?.itemCount ?: -1
            if ((itemCount - 1) > -1) {
                recyclerView?.post {
                    recyclerView?.smoothScrollToPosition(itemCount - 1)
                }
            }
        }
    }

    override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
        super.onAttachedToRecyclerView(recyclerView)
        this.recyclerView = recyclerView
    }

    override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) {
        super.onDetachedFromRecyclerView(recyclerView)
        this.recyclerView = null
    }
}